package org.chuan.hisports.controller;

import com.github.pagehelper.PageInfo;
import org.chuan.hisports.entity.Sporttype;
import org.chuan.hisports.service.SportTypeService;
import org.chuan.hisports.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller("sport")

@RequestMapping("sport")
public class SportTypeController {
    @Autowired
    SportTypeService sts;
    @RequestMapping("insert")
    @ResponseBody
    public JSONResult insert(@RequestParam("type") String type,
                             @RequestParam("day") String day,
                             @RequestParam("total") String total,
                             @RequestParam("endtime") String endtime,
                             @RequestParam("uid") String uid){
       if(type==null||day==null||total==null||endtime==null||uid==null){
           return JSONResult.build(502,"数据有误，请重新上传",null);
       }
       Sporttype sporttype = new Sporttype();
       sporttype.setDay(day);
       sporttype.setType(type);
       sporttype.setTotal(total);
       sporttype.setEndtime(endtime);
       sporttype.setUid(uid);
        System.out.println(sporttype);
        sts.insert(sporttype);
        return  JSONResult.build(200,"success",null);
    }
    @RequestMapping("selectAll")
    @ResponseBody
    public PageInfo<Sporttype> selectAll(@RequestParam("uid") String uid,
                                         @RequestParam("pageNum") Integer pageNum,
                                         @RequestParam("pageSize") Integer pageSize){
        PageInfo<Sporttype>list =  sts.selectAll(pageNum,pageSize,uid);

        return list;
    }

    @RequestMapping("selectByDate")
    @ResponseBody
    public PageInfo<Sporttype> selectByDate(@RequestParam("uid")  String uid,
                                            @RequestParam("date") String date,
                                            @RequestParam("pageNum") Integer pageNum,
                                            @RequestParam("pageSize") Integer pageSize){
        PageInfo<Sporttype> list = sts.selectByDate(pageNum,pageSize,uid,date);
        return list;
    }

    @RequestMapping("selectByType")
    @ResponseBody
    public PageInfo<Sporttype> selectByType(@RequestParam("uid") String uid,
                                            @RequestParam("type") String type,
                                            @RequestParam("pageNum") Integer pageNum,
                                            @RequestParam("pageSize") Integer pageSize){
        PageInfo<Sporttype> list = sts.selectByType(pageNum,pageSize,uid,type);
        return list;
    }

    @RequestMapping("selectWeek")
    @ResponseBody
    public List selectWeek(@RequestParam("uid") String uid){
        List list = sts.selectWeek(uid);
        return list;
    }
    @RequestMapping("selectMonth")
    @ResponseBody
    public List selectMonth(@RequestParam("uid") String uid){
        List list = sts.selectMonth(uid);
        return list;
    }
    @RequestMapping("selectYear")
    @ResponseBody
    public List selectYear(@RequestParam("uid") String uid){
        List list = sts.selecYear(uid);
        return list;
    }
}
